package TestSort;

public class SelectSort {
    public static int[] arr = new int[1_0000];

    public static void selectSort () {
        int i = 0;
        int j = i + 1;
        int k = arr.length - 1;
        while (i < k) {
            int minIndex = i;
            int maxIndex = k;
            while (j < k) {
                if (arr[j] < arr[minIndex]) {
                    minIndex = j;
                }
                if (arr[j] > arr[maxIndex]) {
                    maxIndex = j;
                }
                j++;
            }
            swap(arr, minIndex, i);
            if (maxIndex == i) {
                maxIndex = minIndex;
            }
            swap(arr, maxIndex, k);
            i++;
            k--;
        }
    }

    public static void swap (int[] arr, int a, int b) {
        int tmp = arr[a];
        arr[a] = arr[b];
        arr[b] = tmp;
    }
}
